#include "fig_background.h"
#include "fighter.h"
#include "fig_constants.h"


FIGBackground::FIGBackground(const std::string& Name, 
							 const	math::Vec2& Pos,
							 float	Speed ,
							 float	MoveScaleX,
							 float	Rotation, 
							 float	Scale,
							 int	Layer,
							 COLOR	c
							 ) :
								m_IsToDelete(false)
{


	if(!Name.empty())
	{
		m_Sprite.Create(Name); 	
	}	

	m_Pos = Pos;
	m_Speed = Speed;
	m_MoveScaleX = MoveScaleX;
	// main background is full screen
	if(m_MoveScaleX == 0)
		m_Sprite.m_SizeOriginal = math::Vec2(1.0f,1.0f);
	m_Rotation = Rotation;
	m_Scale = Scale;
	m_Layer = Layer;
	m_Color = c;
}




void	FIGBackground::Render(const math::Vec2& Offset,
							  const math::Vec2& ShakeOffset,
							  float Scale
							  )
{
	
	if(m_IsToDelete)
		return;

	// not reach yet 
	if(m_Pos.y + (m_Sprite.m_SizeOriginal.y*0.5f) < 0 && m_Pos.y + (m_Sprite.m_SizeOriginal.x*0.5f) < 0)
		return;

	// passed already
	if(m_Pos.y - (m_Sprite.m_SizeOriginal.y*0.5f) > 1  && m_Pos.y - (m_Sprite.m_SizeOriginal.x*0.5f) > 1)
		m_IsToDelete = true;
		

	m_Sprite.m_Color = m_Color;

	m_Sprite.m_Pos = m_Pos + (Offset * m_MoveScaleX);
	m_Sprite.m_Pos += ShakeOffset;
	m_Sprite.m_Size = m_Sprite.m_SizeOriginal * Scale * m_Scale;
    

	if(m_Layer < 0)  // Main Background		
	{
		m_Sprite.m_Size.y = 1.0f;
	}

	m_Sprite.m_Rotation = m_Rotation;
	m_Sprite.RenderRotated();
}
	

void	FIGBackground::RenderDebug(const math::Vec2& Offset,float Scale)
{

}
	

void	FIGBackground::Tick(float dt)
{
	if(m_IsToDelete)
		return;
    
    m_Sprite.Tick(dt);

	m_Pos = m_Pos + (math::Vec2(0, m_Speed) * dt );
}


void	FIGBackground::Clear()
{

}


void	FIGBackground::MoveUpForSec(float Seconds)
{
	float Temp = m_Speed * Seconds;
	m_Pos = m_Pos -  math::Vec2(0, Temp);
}

	

